// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

namespace CommunityToolkit.WinUI.Converters;

/// <summary>
/// Value converter that applies NOT operator to a <see cref="bool"/> value.
/// </summary>
public partial class BoolNegationConverter : IValueConverter
{
    /// <summary>
    /// Convert a boolean value to its negation.
    /// </summary>
    /// <param name="value">The <see cref="bool"/> value to negate.</param>
    /// <param name="targetType">The type of the target property, as a type reference.</param>
    /// <param name="parameter">Optional parameter. Not used.</param>
    /// <param name="language">The language of the conversion. Not used</param>
    /// <returns>The value to be passed to the target dependency property.</returns>
    public object Convert(object value, Type targetType, object parameter, string language)
    {
        return !(value is bool && (bool)value);
    }

    /// <summary>
    /// Convert back a boolean value to its negation.
    /// </summary>
    /// <param name="value">The <see cref="bool"/> value to negate.</param>
    /// <param name="targetType">The type of the target property, as a type reference.</param>
    /// <param name="parameter">Optional parameter. Not used.</param>
    /// <param name="language">The language of the conversion. Not used</param>
    /// <returns>The value to be passed to the target dependency property.</returns>
    public object ConvertBack(object value, Type targetType, object parameter, string language)
    {
        return !(value is bool && (bool)value);
    }
}
